package br.edu.ifrn.potigol.lang.nodes;

import java.util.List;

import br.edu.ifrn.potigol.lang.Context;
import br.edu.ifrn.potigol.lang.PotigolException;
import br.edu.ifrn.potigol.lang.PotigolObject;
import br.edu.ifrn.potigol.lang.PotigolRuntime;
import br.edu.ifrn.potigol.lang.ValueObject;

public class ArrayDefinitionNode extends Node {
	private String name;
	private Integer size;
	private List<ValueObject> initialValues;
	
	public ArrayDefinitionNode(String name, int size) {
		this.name = name;
		this.size = size;
		this.initialValues = null;
	}
	
	public ArrayDefinitionNode(String name, List<ValueObject> initialValues) {
		this.name = name;
		this.size = initialValues.size();
		this.initialValues = initialValues;
	}
	
	public ArrayDefinitionNode(String name) {
		this.name = name;
		this.size = null;
		this.initialValues = null;
	}

	@Override
	public PotigolObject eval(Context context) throws PotigolException {
		context.createArray(name, size, initialValues);
		return PotigolRuntime.getNil();
	}

}
